#ifndef GAME_WIDGET_H
#define GAME_WIDGET_H

#include <QWidget>
#include <Qtimer>
#include <QLabel>
#include <memory>
#include <QPushButton>

#include "minesweeprwidget.h"
#include "global_config.h"
#include "mainwidget.h"
#include "score_board.h"

#include "gameresultdialog.h"

#define GAME_WIDGET_SIDE_WIDGET_WIDTH   240
#define GAME_WIDGET_TIMER_WIDGET_HEIGHT 30

class GameWidget : public QWidget, public std::enable_shared_from_this<GameWidget>
{
    Q_OBJECT
public:
    explicit GameWidget(QWidget *parent = nullptr, std::shared_ptr<tcp_client> client = nullptr);

    std::shared_ptr<MineSweeprWidget> mineSweeperWidget() const
    {
        return mineSweeperWidgetPtr_;
    }

    void setMainWidget(std::weak_ptr<MainWidget> mainWidget)
    {
        mainWidgetPtr_ = mainWidget;
    }

    void setTimerLabel()
    {
        timerLabel_.setFixedSize(GAME_WIDGET_SIDE_WIDGET_WIDTH, GAME_WIDGET_TIMER_WIDGET_HEIGHT);
        timerLabel_.move(MINESWEEPER_WIDGET_LENTH, 0);
        timerLabel_.setAlignment(Qt::AlignCenter);
    }

signals:
    /* 其他线程想要调用show()方法时需要通过信号-槽机制触发 */
    void showWindow();

    void showGameResultDiag();

    void refreshScoreBoard();

private:
    std::shared_ptr<MineSweeprWidget> mineSweeperWidgetPtr_;
    std::shared_ptr<tcp_client> clientPtr_;
    std::weak_ptr<MainWidget> mainWidgetPtr_;
    QTimer timer_;
    GameResultDialog gameResultDialog_;
    uint32_t seconds_ = 0;
    QLabel timerLabel_;

    score_board scoreBoardPlayer1_;
    score_board scoreBoardPlayer2_;

    /* for debug */
    QPushButton click_all_pos_;
};


#endif // GAME_WIDGET_H